import { defineConfig } from "vite";

import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import IconsResolver from "unplugin-icons/resolver";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import Icons from "unplugin-icons/vite";

import path from "path";
import { create } from "domain";

const pathSrc = path.resolve(__dirname, "src");

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // 添加SVG图标插件
    createSvgIconsPlugin({
      iconDirs: [path.resolve(pathSrc, "assets/icons")],
      symbolId: "icon-[dir]-[name]",
    }),
    AutoImport({
      resolvers: [
        // 自动导入 Element Plus 相关函数
        ElementPlusResolver(),
        // 自动导入图标组件
        IconsResolver({}),
      ],
      // 是否在vue模板中自动导入
      vueTemplate: true,
      // 自动导入vue相关函数,如: ref, reactive, toRaw等
      imports: ["vue"],
      eslintrc: {
        enabled: true, // 是否自动生成eslint规则，生成之后设置false
        filepath: "./.eslintrc-auto-import.json", // 指定自动导入函数eslint规则的文件
      },
      dts: path.resolve(pathSrc, "types", "auto-imports.d.ts"), //指定自动导入函数TS类型声明文件路径
    }),
    Components({
      resolvers: [
        // 自动导入 Element Plus 组件
        ElementPlusResolver(),
        // 自动导入图标组件
        IconsResolver({
          prefix: "Icon",
        }),
      ],
      dts: path.resolve(pathSrc, "types", "components.d.ts"), //指定自动导入组件TS类型声明文件路径
    }),
  ],
  // webpack 配置对象中的 resolve（解析）配置项，用于控制模块路径的解析行为
  resolve: {
    // alias（别名）配置项：为模块路径设置快捷别名，避免复杂相对路径
    alias: {
      // 键是别名（如 "@"），值是实际替换的路径
      '@': path.resolve(__dirname, 'src'), 
    },
  },
});
